<template>
	<view class="change-password-page">
		<u-field v-model="password" label="新密码" placeholder="请填写密码" :error-message="errMsg" @input="handleInput" />

		<view class="btn" @click="submit">
			<text>提交</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				errMsg: ''
			};
		},
		methods: {
			handleInput(val) {
				this.errMsg = val.length < 6 ? '密码不能小于6位' : ''
			},
			
			submit() {
				const {password} = this
				this.$u.post('/modifypassword', {password}).then(res => {
					uni.showToast({
						title: '修改成功'
					})
					
					this.$u.vuex('vuex_user', {})
					this.$u.vuex('vuex_token', '')
					uni.clearStorage()
					
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/login/login'
						})
					}, 1500)
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.change-password-page {
		padding: 30rpx;

		.btn {
			margin: 20rpx auto 0 auto;
			width: 652rpx;
			height: 84rpx;
			background: #3D99BB;
			border-radius: 54rpx;
			background-color: #3D99BB;
			font-size: 32rpx;
			font-weight: bold;
			line-height: 84rpx;
			color: #FFFFFF;
			text-align: center;
			transform: scale(1);
			transition: transform 0.1s linear;
			
			&:active {
				transform: scale(0.9)
			}
		}

	}
</style>
